package bairui.international.console.web.controller.product.category.product;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.project.commons.util.Util_FileDeal;
import com.lianjing.sh.project.commons.util.Util_FileDeal.FileInfo;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.sh_lianjing.util.Util_BeanCopyByDeclaredProperties;

import bairui.international.model.domain.jpa.TB_Product;
import bairui.international.service.Service_Product;

/**
 *
 * 物料添加
 *
 * @generated
 * 
 * @see STest_C_Product_Category_ProductAdd_Add 测试
 *
 */
@Controller
public class C_Product_Category_ProductAdd_Add
 extends SC_Product_Category_ProductAdd_Add 
{
	
	@Autowired private Service_Product service_Product;
	
	/**
	 * 添加
	 */
	@Action(Add.class)
	@PostMapping(Add.RequestMappingValue)
	public @FomatOutput @ResponseBody Object add(
		@Valid Add.InputModel input, 
		@PathVariable(name=Add.PathVariableName.CategoryId) long categoryId
	) throws Exception {
		TB_Product bean = new TB_Product();
		// 保存图片相关
		FileInfo fileInfo = Util_FileDeal.saveFile(input.getImgUrlFile(), pathConfig.getPosition_Image_Product());
		bean.setImgUrl(fileInfo.getName());
		// 保存数据
		TB_Product result = service_Product.savePriceProduct(
				categoryId,
				Util_BeanCopyByDeclaredProperties.copyProperties(input, bean)
			);
		//
		return result.getId();
	}
	

}
